home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 101 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. From: clamage@Eng.Sun.COM (Steve Clamage)
  2. Message-ID: <4e0u1s$5fv@engnews1.Eng.Sun.COM>
  3. X-Original-Date: 22 Jan 1996 21:02:52 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 22 Jan 96 22:23:37 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Why no allocator-specific delete?
  9. Organization: Sun Microsystems Inc.
  10. References: <4dvid8$460@news.bridge.net>
  11. Reply-To: clamage@Eng.Sun.COM
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMQQOguEDnX0m9pzZAQGEOwF+OnlD3HPFcFdNRZMBcj4g1bBodijQqOM3
  14.     CPsTEoHASx1Ou7RP5L8r9WHZU7ISMSyo
  15.     =ezyv
  16.  
  17. In article 460@news.bridge.net, David Byrden <100101.2547@compuserve.com>
  18. writes:
  19. >Why, in the Septenber draft standard, is an allocator-specific verrion of 
  20. >'new' provided;
  21. >
  22. >20.1.4.4
  23. >
  24. >           new(x) T    
  25. >
  26. >    returns an X::types<T>::pointer, where x is of an 
  27. >    allocator type X
  28.  
  29. You are actually referring to the "placement new" syntax not having a
  30. corresponding "placement delete" syntax.
  31.  
  32. No good syntax was found for such. The obvious syntax
  33.     delete (x) p;
  34. leads to too many ambiguities. More importantly, it means that the
  35. point of deletion would somehow have to know what placement version
  36. of "new" was used and what the parameters were. Needing that knowledge
  37. would make "placement delete" unsafe and hard to use. (Consider the
  38. general case where the "new" and "delete" expressions are in different
  39. compilation units, and the parameters to "new" affect how "delete"
  40. should be called.)
  41.  
  42. You can define a version of "operator delete()" corresponding to a
  43. placement new. If the constructor for the object exits via an exception,
  44. the compiler will call the corresponding placement delete automatically
  45. as a special case.
  46.     T* p = new (x) T;
  47. The reasons for this special case are
  48. 1. You do not know what needs to be deleted in general, but the compiler does.
  49. 2. The compiler has all the information it needs to invoke the special
  50. operator delete() correctly. It is invoked at the point of the new-expression.
  51.  
  52. >but there is no matching version of 'delete'? Are we supposed to use both 
  53. >destroy() and deallocate() to get rid of that object?
  54.  
  55. Yes. In the above example:
  56.     p->~T();
  57.     operator delete(p, x);
  58.  
  59. ---
  60. Steve Clamage, stephen.clamage@eng.sun.com
  61. ---
  62. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  63.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  64.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  65.